package searchingtester;

import java.util.Random;

/**
 *
 * @author Seba
 */
public class Test {
    
    public static void main(String[] args) {
        performTests(105000,200000);
        
    }
    
    private static void performTests(int minSize, int maxSize){
        Search s = new Search();
        int seek;
        int[] array;
        int result;
        int step = 5000;
        int maxRandomSearches;
        for(int i = minSize; i<= maxSize; i=i+step){
            array = generateSortedArray(i);
            //RANDOM SEEK for j=0;
            seek = getNumberToSearchFor(i);
//            seek = 0;
//            result = s.linearSearch(array, seek);
            result = s.invokeBinarySearch(array,seek);
            System.out.print(i+";"+s.getComparisonCounter());
//            maxRandomSearches = i;
            maxRandomSearches = 100;
            for(int j = 1; j < maxRandomSearches; j++){
//                seek = j;
                seek = getNumberToSearchFor(i);
//                result = s.linearSearch(array, seek);
//                System.out.println("Looking for: "+seek+" in array in"
//                    +array.length+" long array with linear search returns "+result
//                        +" comparing: "+s.getComparisonCounter()+" times");
                result = s.invokeBinarySearch(array,seek);
//                System.out.println("Looking for: "+seek+" in array in"
//                    +array.length+" long array with binary search returns "+result
//                        +" comparing: "+s.getComparisonCounter()+" times");
                System.out.print(";"+s.getComparisonCounter());
                
            }
            System.out.print("\n");
        }
    }
    
    private static int[] generateSortedArray(int size){
        int[] array = new int[size];
        for(int i = 0; i < size; i++){
            array[i] = i;
        }
        return array;
    }
    
    private static int getNumberToSearchFor(int max){
        Random generator = new Random();
        return generator.nextInt(max);
    }
}
